Skip to content

nginx配置https h2 h3

nginx
server
    {      
      http2 on;
      # 开启http3  
     listen 443 quic;
     listen [::]:443 quic ; 
     add_header Alt-Svc 'h3=":443"; ma=86400';
     ssl_stapling on;
     ssl_stapling_verify on; 
     
      server_name  kiwi233.top;
      # ssl证书地址
      ssl_certificate ./fullchain.pem;
      ssl_certificate_key ./cert.key;# key文件的路径
      
      # ssl验证相关配置
      ssl_session_timeout 5m;    #缓存有效期
      ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;    #加密算法
      ssl_protocols TLSv1.3;    #安全链接可选的加密协议
      ssl_prefer_server_ciphers on;   #使用服务器端的首选算法
       设置是否允许 cookie 传输
      add_header Access-Control-Allow-Credentials true;
      # 允许请求地址跨域 * 做为通配符
       add_header Access-Control-Allow-Origin * always;
      # 允许跨域的请求方法
      add_header Access-Control-Allow-Methods 'GET, POST, PUT,DELET,OPTIONS';
      add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToke,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
      if ($request_method = 'OPTIONS') {
           return 204;
      } 
       location / {
           proxy_pass http://127.0.0.1:4000;
            # 设置代理服务器的协议头,获取真实IP
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;   
       }
    }

采用 Apache-2.0 license 协议